<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录页面</title>
</head>
<body>
<h1>用户登录</h1>
用户名：<input name="username" type="text" id="username"><br>
密码:<input name="password" type="text" id="password"><br>
<input type="button" value="登录" onclick="login()">
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script>
    function login() {
        $.ajax({
            type: "post",
            url: "/user2/login",
            data: {
                username: $("#username").val(),
                password: $("#password").val()
            },
            //http 请求成功
            success: function(result){
                if(result){
                    //密码正确
                    location.href = "index.html";
                    // location.assign("index.html");
                }else{
                    //密码错误
                    alert("密码错误, 请确认");
                }
            }
        });
    }

</script>
</body>
</html>